//
//  LRHeaderView.m
//  本地生活圈
//
//  Created by admin on 15/8/15.
//  Copyright (c) 2015年 懒人. All rights reserved.
//

#import "LRHeaderView.h"
#import "UIButton+WebCache.h"


@interface LRHeaderView ()
@property (weak, nonatomic) IBOutlet UIButton *IconBtn;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *starImage;
@property (weak, nonatomic) IBOutlet UIButton *shareButton;
@property (weak, nonatomic) IBOutlet UILabel *introLabel;
@property (weak, nonatomic) IBOutlet UIButton *localButton;
@property (weak, nonatomic) IBOutlet UIButton *phoneButton;

@end

@implementation LRHeaderView

- (void)setDetailModel:(LRDetailFamousModel *)detailModel
{
    _detailModel = detailModel;
    
    // todo
    [self.IconBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:detailModel.cover] forState:UIControlStateNormal];

    self.titleLabel.text = detailModel.name;
    
    NSString *imageName = [NSString stringWithFormat:@"star_%d",detailModel.score];
    [self.starImage setImage:[UIImage imageNamed:imageName]];
    
    self.shareButton.layer.cornerRadius = 5;
    
    self.introLabel.text = detailModel.intro;
    [self.localButton setTitle:detailModel.address forState:UIControlStateNormal];
    [self.phoneButton setTitle:detailModel.phone forState:UIControlStateNormal];
    
    CGRect rect = [detailModel.intro boundingRectWithSize:CGSizeMake(kUIScreenW, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:14]} context:nil];
    self.height = 135 + rect.size.height;
}

// 分享
- (IBAction)shareClick {
    if ([self.delegate respondsToSelector:@selector(headerShare)])
    {
        [self.delegate headerShare];
    }
}

// 导航
- (IBAction)location {
    if ([self.delegate respondsToSelector:@selector(locationUpdateWithAdress:)])
    {
        [self.delegate locationUpdateWithAdress:self.detailModel.address];
    }
}

// 电话拨打
- (IBAction)callPhone {
    if ([self.delegate respondsToSelector:@selector(headerCallPhoneWithPhone:)])
    {
        [self.delegate headerCallPhoneWithPhone:self.detailModel.phone];
    }
}

@end
